class Food {

}
class Fruit extends Food {

}
class Apple extends Fruit {

}

class Banana extends Fruit {

}

class Message<T> { // 设置泛型
	private T message ;

	public T getMessage() {
		return message;
	}

	public void setMessage(T message) {
		this.message = message;
	}
}

public class TestDemo {
 	public static void main(String[] args) {
 		Message<Apple> message = new Message<>() ;
 		message.setMessage(new Apple());
 		fun(message);
 
		Message<Banana> message2 = new Message<>() ;
 		message2.setMessage(new Banana());
 		fun(message2);
 	}
 	
 	public static void fun(Message<? extends Fruit> temp) {
 		//temp.setMessage(new Banana()); //仍然无法修改！
 		//temp.setMessage(new Apple()); //仍然无法修改！
		//temp.setMessage(new Fruit());//任然无法修改

 		Fruit fruit = temp.getMessage();
		//Apple apple = temp.getMessage();//报错
 	}

	 public static void func(Message<? super Fruit> temp) {
		 temp.setMessage(new Apple());//ok
		 temp.setMessage(new Fruit());//ok
		 temp.setMessage(new Banana());//ok

		 //Fruit fruit = temp.getMessage();//报错
		 //Apple apple = temp.getMessage();//报错
	 }
}